//uuid函数
/*
@params len字符串长度
@params radix 规定了从前多少位选择随机数
*/
function uuid(len, radix) {
  var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
  var uuid = [],
    i;
  radix = radix || chars.length;
  if (len) {
    // Compact form
    for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
  } else {
    // rfc4122, version 4 form
    var r;
    // rfc4122 requires these characters
    uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
    uuid[14] = '4';
    // Fill in random data. At i==19 set the high bits of clock sequence as
    // per rfc4122, sec. 4.1.5
    for (i = 0; i < 36; i++) {
      if (!uuid[i]) {
        r = 0 | Math.random() * 16;
        uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
      }
    }
  }
  return uuid.join('');
}

//继承用 
/*
@params superType 父类
@params subType 子类
*/
function inherit(superType, subType) {
  var F = function() {};
  F.prototype = superType.prototype;
  subType.prototype = new F();
  subType.prototype.constructor = subType;
}

//集合函数增，删，改，查
function Collection(){
    this.json={};
}
Collection.prototype={
    constructor:Collection,
    //增加
    addEl:function(key,name){
        this.json[key]=name;
    },
    //删除
    deleteEl:function(key){
        delete this.json[key];
    },
    //更新
    updateEl:function(){

    },
    //清空
    emptyEl:function(){
        this.json={};
    },
    //获取json对象
    getEls:function(){
        return this.json;
    },
    //获取所有的key数组
    getKeys:function(){
        return Object.keys(this.json);
    }
}

//获取集合
//input:obj,[],other
//return {name1:[],name2：[]}
function getAttrs(){
    var obj=arguments[0];//操作对象
    var attrNames=arguments[1];//对象的属性名集合
    var other=arguments[2];//其他属性值
    //获取到每个value值，分别放到不同的数组里面
    var collection=new Collection();
    for(var i=0;i<attrNames.length;i++){
        collection.addEl(attrNames[i],[]);
        var attrVal=$(obj).attr(attrNames[i]);
        collection.getEls()[attrNames[i]].push(attrVal);
        if(other){
           collection.getEls()[attrNames[i]].push(other); 
        }       
    }
    return collection.getEls();
}

//获取集合中的属性
function getIdCollection(json,val){
    var keys=Object.keys(json);
    var arr=[];
    for(var i=0;i<keys.length;i++){
        if(json[keys[i]][val]){
            arr.push(json[keys[i]][val]);
        }
        
    }
    return arr;
}

//补零函数
function toDou(n){
  return n<10 ? '0'+n : ''+n;
}

//随机整数
function rnd(n,m){
  return Math.floor(Math.random()*(m-n)+n);
}

//获取坐标轴需要数据
//arr=[['1:00',10],['2:00',10]] 后台传过来的数据格式,返回相应的坐标值
function getAxis(arr){
    var dataY=[];
    var dataX=[];
    for(var i=0;i<arr.length;i++){
        dataY[i]=arr[i][1];
        dataX[i]=arr[i][0];
    }
    return {
        dataX:dataX,
        dataY:dataY
    }
}

//设置本地存储
function setStore(name, objData) {
  var str = JSON.stringify(objData);
  localStorage.setItem(name, str);
}

//获取本地存储
function getStore(name) {
  var obj = JSON.parse(localStorage.getItem(name));
  return obj;
}


//格式化时间戳
function formatterTime(timeStamp){
    var date = new Date(Number(timeStamp)); 
    var arr=[toDou(date.getHours()),toDou(date.getMinutes())];
    return arr.join(':');
}

function getSectionTime(end,day){
    //获取结束时间的年月日 =》时间戳
    var oDate=new Date(end);
    var oYear=oDate.getFullYear();
    var oMonth=oDate.getMonth();
    var oDay=oDate.getDate();
    oDate=new Date(oYear,oMonth,oDay);
    var endTimeStamp=oDate.getTime(oDate);
    //差值
    var difference=day*24*60*60*1000;
    //开始时间
    var startTimeStamp=endTimeStamp-difference;
    //console.log(new Date(startTimeStamp));
    return {
        start:startTimeStamp,
        end:endTimeStamp
    }   
}
function getSectionhour(end,hour){
    //获取结束时间的年月日 =》时间戳
    var oDate=new Date(end);
    var oYear=oDate.getFullYear();
    var oMonth=oDate.getMonth();
    var oDay=oDate.getDate();
    oDate=new Date(oYear,oMonth,oDay);
    var endTimeStamp=oDate.getTime(oDate);
    //差值
    var difference=hour*60*60*1000;
    //开始时间
    var startTimeStamp=endTimeStamp-difference;
    //console.log(new Date(startTimeStamp));
    return {
        start:startTimeStamp,
        end:endTimeStamp
    }
}
//数组转json
function arrtoJson(data,arg){
    if(arg=='mdhm'){
        var arr =[];
        var arrDay = [];
        var arrtime =[];
        var arrMark =[];
        for(var i=0;i<data.length;i++){
            var date = new Date(Number(data[i]));
            arrDay[i]=[toDou(date.getMonth()+1),toDou(date.getDate())].join('-');
            arr[i]=[toDou(date.getHours()),toDou(date.getMinutes())].join(':');
            arrtime.push((arrDay[i]+' '+arr[i]));
            var temp = {xAxis:arrtime[i]};
            arrMark.push(temp)
        }
        return arrMark
    }else if(arg=='hm'){
            var arr =[];
            var arrMark =[];
            for(var i=0;i<data.length;i++){
                var date = new Date(Number(data[i]));
                arr[i]=[toDou(date.getHours()),toDou(date.getMinutes())].join(':');
                arr.push(arr[i]);
                var temp = {xAxis:arr[i]};
                arrMark.push(temp)
            }
            return arrMark
    }

}


/*
var date = new Date(Number(item));
var arrDay=[toDou(date.getMonth()+1),toDou(date.getDate())];
var arr=[toDou(date.getHours()),toDou(date.getMinutes())];
return arrDay.join('-')+' '+arr.join(':');*/
